package service

import (
	"context"
	"exam/6.11/api/request"
	"exam/6.11/model"
	"exam/6.11/model/dao"
	"github.com/google/uuid"
)

type IOtherService interface {
	Find(ctx context.Context, req *request.Form) []model.Supplier
	Add(ctx context.Context, req *request.ProductForm) error
}

type OtherService struct {
	dao *dao.OtherDao
}

func (o *OtherService) Find(ctx context.Context, req *request.Form) []model.Supplier {

	find := o.dao.Find(ctx, req.Name, req.Contacts, req.Area, req.CreateBy, req.Page, req.PageSize)
	return find
}
func (o *OtherService) Add(ctx context.Context, req *request.ProductForm) error {

	code := uuid.NewString()
	product := model.Product{
		Name:        req.Name,
		Code:        code,
		Group:       req.Group,
		RuleModel:   req.RuleModel,
		Unit:        req.Unit,
		CostPrice:   req.CostPrice,
		MarketPrice: req.MarketPrice,
		Status:      req.Status,
		Notes:       req.Notes,
		Image:       req.Image,
		Stock:       req.Stock,
	}

	err := o.dao.Add(product)
	if err != nil {
		return err
	}
	return nil
}

func NewIOtherService(dao *dao.OtherDao) IOtherService {
	return &OtherService{dao: dao}
}
